package com.cheney.mapboxexample.common;

import android.app.Application;
import android.content.Context;
import android.util.Log;

public class MyApplication extends Application {
    private static final String TAG = "MyApplication";
    private static Context mContext;

    private static int mScreenWidthPixels = 0;
    private static int mScreenHeightPixels = 0;

    private static int mStateBarHeight = 0;
    private static int mNavigationBarHeight = 0;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = getApplicationContext();  // 获取全局Context

        getScreenResolution();
        getStatusBarHeight();
    }

    private void getScreenResolution(){
        mScreenWidthPixels = mContext.getResources().getDisplayMetrics().widthPixels;
        mScreenHeightPixels = mContext.getResources().getDisplayMetrics().heightPixels;
        Log.i(TAG,"ScreenPixels, Width:" + mScreenWidthPixels
                + "  Height:" + mScreenHeightPixels);
    }

    private void getStatusBarHeight() {
        int h = mContext.getResources().getDimensionPixelSize(
                mContext.getResources().getIdentifier("status_bar_height", "dimen", "android"));
        mStateBarHeight = Math.max(h, 0);

        h = mContext.getResources().getDimensionPixelSize(
                mContext.getResources().getIdentifier("navigation_bar_height", "dimen", "android"));
        mNavigationBarHeight = Math.max(h, 0);
    }

    public static Context getContext(){
        return mContext;
    }

    public static int getScreenWidthPixels() {
        return mScreenWidthPixels;
    }

    public static int getScreenHeightPixels() {
        return mScreenHeightPixels;
    }

    public static int getStateBarHeight() {
        return mStateBarHeight;
    }

    public static int getNavigationBarHeight() {
        return mNavigationBarHeight;
    }
}
